package com.dowsure.apisaas.api;

import com.dowsure.apisaas.enums.MethodEnums;
import com.dowsure.apisaas.exception.ApiException;
import com.dowsure.apisaas.model.LoanCloseRequestParams;
import com.dowsure.apisaas.model.LoanOverdueDataRequestParams;
import com.dowsure.apisaas.model.LoanRepaymentPlanRequestParams;
import com.dowsure.apisaas.model.RepaymentRequestParams;
import com.dowsure.apisaas.util.ApiClient;
import com.dowsure.apisaas.util.ApiResponse;
import com.dowsure.apisaas.util.RequestParamValidatedUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: 贷款
 * @author: Dowsure
 * @create: 2022-02-15 15:25
 **/
public class LoanApi {

    private ApiClient apiClient;

    public LoanApi(ApiClient apiClient){
        this.apiClient = apiClient;
    }


    /**
     * 10、传输还款计划（API-C09）
     * 用户传递还款计划给Dowsure。
     *    a.需要提供支用的合同编号。
     *    b.需要提供划款计划数据。
     * @author Dowsure
     * @param loanRepaymentPlanRequestParams {@link LoanRepaymentPlanRequestParams}
     * @return {@link ApiResponse <String>}
     * @throws ApiException
     */
    public ApiResponse<Void> repaymentPlan(LoanRepaymentPlanRequestParams loanRepaymentPlanRequestParams) throws ApiException {
        RequestParamValidatedUtils.validated(loanRepaymentPlanRequestParams);
        String localVarPath = "/v1/loan/repayment-plan";

        Map<String, String> headerParams = new HashMap<>();
        com.squareup.okhttp.Call call = apiClient.buildCall(localVarPath, MethodEnums.POST, loanRepaymentPlanRequestParams, headerParams);
        return apiClient.execute(call);
    }


    /**
     * 11、传输还款数据（API-C10）
     * 卖家在用户侧主动还款后，用户需要把还款数据同步给Dowsure。
     * @author Dowsure
     * @param repaymentRequestParams {@link RepaymentRequestParams}
     * @return {@link ApiResponse <String>}
     * @throws ApiException
     */
    public ApiResponse<String> repayment(RepaymentRequestParams repaymentRequestParams) throws ApiException {
        RequestParamValidatedUtils.validated(repaymentRequestParams);
        String localVarPath = "/v1/loan/repayment";

        Map<String, String> headerParams = new HashMap<>();
        com.squareup.okhttp.Call call = apiClient.buildCall(localVarPath, MethodEnums.POST, repaymentRequestParams, headerParams);
        return apiClient.execute(call);
    }


    /**
     * 13、传输结清支用请求（API-C12）
     * 当卖家结清支用，用户需要调用此接口完成结清支用操作
     * @author Dowsure
     * @param loanCloseRequestParams {@link LoanCloseRequestParams}
     * @return {@link ApiResponse <String>}
     * @throws ApiException
     */
    public ApiResponse<String> close(LoanCloseRequestParams loanCloseRequestParams) throws ApiException {
        RequestParamValidatedUtils.validated(loanCloseRequestParams);
        String localVarPath = "/v1/loan/close";

        Map<String, String> headerParams = new HashMap<>();
        com.squareup.okhttp.Call call = apiClient.buildCall(localVarPath, MethodEnums.POST, loanCloseRequestParams, headerParams);
        return apiClient.execute(call);
    }


    /**
     * 21、传输每日逾期数据（API-C16）
     * 当卖家结清支用，用户需要调用此接口完成结清支用操作
     * @author Dowsure
     * @param loanOverdueDataRequestParams {@link LoanOverdueDataRequestParams}
     * @return {@link ApiResponse <String>}
     * @throws ApiException
     */
    public ApiResponse<String> overdueData(List<LoanOverdueDataRequestParams> loanOverdueDataRequestParams) throws ApiException {
        RequestParamValidatedUtils.validated(loanOverdueDataRequestParams);
        String localVarPath = "/v1/loan/overdue-data";

        Map<String, String> headerParams = new HashMap<>();
        com.squareup.okhttp.Call call = apiClient.buildCall(localVarPath, MethodEnums.POST, loanOverdueDataRequestParams, headerParams);
        return apiClient.execute(call);
    }

    /**
     * 22、传输支用关闭&授信关闭请求（API-C22）
     * 用户可以调用该接口完成支用结清和授信关闭操作
     * @author Dowsure
     * @param loanCloseallRequestParams {@link LoanCloseallRequestParams}
     * @return {@link ApiResponse <String>}
     * @throws ApiException
     */
    public ApiResponse<String> closeall(LoanCloseallRequestParams loanCloseallRequestParams) throws ApiException {
        RequestParamValidatedUtils.validated(loanCloseallRequestParams);
        String localVarPath = "/v1/loan/closeall";
        Map<String, String> headerParams = new HashMap<>();
        com.squareup.okhttp.Call call = apiClient.buildCall(localVarPath, MethodEnums.POST, loanCloseallRequestParams, headerParams);
        return apiClient.execute(call);
    }

}
